<?php
namespace LoggerOne\Handler;

class MySQLHandler implements Handler
{
    protected $db;
    
    protected $table_name;
    
    
    public function __construct(string $table_name, object $dbHandle = null)
    {
        $this->table_name = $table_name;
        $this->db = $dbHandle;
    }
    
    public function write($messages)
    {
        $batchData = [];
        foreach ($messages as $level => $message) {
            $batchData[] = ['level' => $level, 'message' => $message, 'created' => time()];
        }
        $this->db->insertBatch($this->table_name, $batchData);
    }
}